package threading;

import java.util.concurrent.ArrayBlockingQueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo19 {
    public static void main(String[] args) throws InterruptedException {
        //BlockingDeque两种实现方式
        //1.基于数组实现阻塞队列
        //BlockingQueue<String> queue = new ArrayBlockingQueue<>(100);//capacity括号中的100表示的是容量。
        //2、基于链表实现阻塞队列
        BlockingQueue<String> queue = new LinkedBlockingDeque<>();
        //1.put入队列
        queue.put("hello1");
        queue.put("hello2");
        queue.put("hello3");
        queue.put("hello4");
        queue.put("hello5");
        //2.take出队列
        String result = null;
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
        result = queue.take();
        System.out.println(result);
    }
}
